<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>高级选择符与遍历</title>
</head>
<body>
    <script>
        function selected() {
            $(document).ready(function () {
                $('#topics a').click(function (e) {
                    e.preventDefault();
                    $('#topics a.selected').removeClass('selected');
                    $(this).addClass('selected');
                });
            });
        }

        function filter() {
            $(document).ready(function () {
                $('#topics a').click(function (e) {
                    e.preventDefault();
                    $('#topics a.selected').removeClass('selected');
                    $(this).addClass('selected');

                    var topic = $(this).text().toLowerCase();
                    $('#news tr').show();
                    if (topic !== 'All') {
                        $('#news tr:has(td):not(:contains("' + topic + '"))').hide();
                    }
                });
            });
        }

        function exclude() {
            $(document).ready(function () {
                $('#topics a').click(function (e) {
                    e.preventDefault();
                    $('#topics a.selected').removeClass('selected');
                    $(this).addClass('selected');

                    var topic = $(this).text().toLowerCase();
                    $('#news tr').show();
                    if (topic !== 'All') {
                        $('#news').find('tr:has(td)').not(function () {
                            return $(this).children(':nth-child(4)').text().toLowerCase() === topic;
                        }).hide();
                    }
                });
            });
        }

        function even() {
            $(document).ready(function () {
                $('#news').find('tr:nth-child(even)').addClass('alt');
            });
        }

        function divide() {
            $(document).ready(function () {
                $('#news tr').filter(function (index) {
                    return (index % 4) < 2;
                }).addClass('alt');
            });
        }

        function alt() {
            $(document).ready(function () {
                $('#news tbody').each(function () {
                    $(this).children().has('td').filter(function (index) {
                        return (index % 4) < 2;
                    }).addClass('alt');
                });
            });
        }

        function stripe() {
            $(document).ready(function () {
                function stripe() {
                    $('#news').find('tr.alt').removeClass('alt');
                    $('#news tbody').each(function () {
                        $(this).children(':visible').has('td')
                            .filter(function (index) {
                                return (index % 4) / 2;
                            }).addClass('alt')
                    });
                }

                stripe();

                $('#topics a').click(function (e) {
                    e.preventDefault();
                    var topic = $(this).text();
                    $('#topics a.selected').removeClass('selected');
                    $(this).addClass('selected');
                    $('#news').find('tr').show();
                    if (topic !== 'All') {
                        $('#news').find('tr:has(td)').not(function () {
                            return $(this).children(':nth-child(4)').text() === topic;
                        }).hide();
                    }
                    stripe();
                });
            });
        }

        function expr() {
            (function ($) {
                $.extend($.expr[':'], {
                    group: function (element, index, matches, set) {
                        var num = parseInt(matches[3], 10);
                        if (isNaN(num)) {
                            return false;
                        }
                        return index % (num * 2) < num;
                    }
                });
            })(jQuery);
        }

        function userExpr() {
            $(document).ready(function () {
                function stripe() {
                    $('#news').find('tr.alt').removeClass('alt');
                    $('#news tbody').each(function () {
                        $(this).children(':visible').has('td').filter(':group(3)').addClass('alt');
                    });
                }

                stripe();
            });
        }

        function property() {
            $(document).ready(function () {
                var $cell = $('#release');
                $cell.addClass('highlight');
                console.log($cell.context);
                console.log($cell.selector);
                console.log($cell.prevObject);
            });
        }

        function propertyCall() {
            $(document).ready(function () {
                var $cell = $('#release').nextAll();
                $cell.addClass('highlight');
                console.log($cell.context);
                console.log($cell.selector);
                console.log($cell.proveObject);
            });
        }

        function addBack() {
            $(document).ready(function () {
                $('#release').nextAll().addBack().addClass('highlight');
            });
        }

        function column() {
            $.fn.column = function () {
                var $cells = $();
                this.each(function () {
                    var $td = $(this).closest('td, th');
                    if ($td.length) {
                        var colNumber = $td[0].cellIndex + 1;
                        var $columnCells = $td
                            .closest('table')
                            .find('td, th')
                            .filter(':nth-child(' + colNumber + ')');
                        $cells = $cells.add($columnCells);
                    }
                });
                return this.pushStack($cells);
            }
        }

        function active() {
            $(document).ready(function () {
                $('#news td').click(function () {
                    $('#news td.active').removeClass('active');
                    $(this).column().addClass('active');
                });
            });
        }

        function end() {
            $(document).ready(function () {
                function stripe() {
                    $('#news')
                        .find('tr.alt').removeClass('alt').end()
                        .find('tbody').each(function () {
                            $(this).children(':visible').has('td')
                                .filter(':group(3)').addClass('alt');
                        });
                }

                stripe();
            });
        }

        function cache() {
            $(document).ready(function () {
                var $news = $('#news');

                function stripe() {
                    $news.find('tr.alt').removeClass('alt');
                    $news.find('tbody').each(function () {
                        $(this).children(':visible').has('td')
                            .filter(':group(3)').addClass('alt');
                    });
                }

                stripe();
            });
        }
    </script>
</body>
</html>